package com.comet.mapper;

import com.comet.domain.Course;
import com.comet.domain.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

public interface ShardingMapper {

    @Select("select * from t_course")
    List<Course> findCourseAll();

    @Insert("insert into t_course(course_name,course_desc,price,status,logo_url,category,remark) values(#{courseName},#{courseDesc},#{price},#{status},#{logoUrl},#{category},#{remark})")
    void addCourse(Course course);

    @Insert("insert into t_order(user_id,course_id, course_name, course_desc, price, logo_url, create_time,remark)  values(#{userId},#{courseId},#{courseName},#{courseDesc},#{price},#{logoUrl},#{createTime},#{remark})")
    void addOrder(Order order);

    @Select("<script>"
            + "SELECT * FROM t_order WHERE order_id IN "
            + "<foreach item='item' index='index' collection='list'      open='(' separator=',' close=')'>"
            + "#{item}"
            + "</foreach>"
            + "</script>")
    List<Order> findCourseIn(@Param("list") List<Long> list);

    @Select("select * from t_order where order_id between #{start} and #{end}")
    List<Order> findOrderRange(@Param("start") Long start, @Param("end") Long end);

    @Select("select * from t_order where order_id = #{orderId}")
    Order findOrderOne(Long orderId);

    @Select("select * from t_order")
    List<Order> findOrderAll();

}
